package com.mallcai.bigdata.ladon.controller.report.form;

import com.mallcai.bigdata.ladon.dpl.entity.report.ReportSql;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * Created by oneape<oneape15@163.com>
 * Created 2019-07-17 16:26.
 * Modify:
 */
@Data
public class ReportSqlForm {
    @NotNull(message = "sql主键为空", groups = {IdCheck.class})
    private Long    sqlId;         // sql主键Id
    @NotNull(message = "数据源Id为空", groups = {SaveCheck.class})
    private Long    dsId;          // 依赖的数据源Id
    @NotNull(message = "是否缓存标志为空", groups = {SaveCheck.class})
    private Integer cached;        // 是否需要缓存; 0 - 不需要; 1 - 需要
    private Integer cachedTime;    // 缓存时间(秒)
    private Integer timeout;       // 超时时间(秒)
    @NotBlank(message = "SQL内容为空", groups = {SaveCheck.class})
    private String  text;          // sql内容
    @NotNull(message = "记录详细日志标志为空", groups = {SaveCheck.class})
    private Integer needDetailLog; // 是否需要详细运行日志, 0 - 不需要(只记录运行耗时、运行错误信息), 1 - 记录运行sql及所有默认信息
    private String  comment;       // 描述信息

    @NotNull(message = "报表主键为空", groups = {SaveCheck.class})
    private Long reportId;      // 报表主键Id

    public interface IdCheck {
    }

    public interface SaveCheck {
    }

    public ReportSql toEntity() {
        ReportSql rs = new ReportSql();
        BeanUtils.copyProperties(this, rs);
        rs.setId(sqlId);
        return rs;
    }
}
